{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[('Twenty', 'O'), ('miles', 'O'), ('east', 'O'), ('of', 'O'), ('Reno', 'LOCATION'), (',', 'O'), ('Nev.', 'LOCATION'), (',', 'O'), ('where', 'O'), ('packs', 'O'), ('of', 'O'), ('wild', 'O'), ('mustangs', 'O'), ('roam', 'O'), ('free', 'O'), ('through', 'O'), ('the', 'O'), ('parched', 'O'), ('landscape', 'O'), (',', 'O'), ('Tesla', 'ORGANIZATION'), ('Gigafactory', 'ORGANIZATION'), ('1', 'O'), ('sprawls', 'O'), ('near', 'O'), ('Interstate', 'LOCATION'), ('80', 'LOCATION'), ('.', 'O')]\n"
     ]
    }
   ],
   "source": [
    "import nltk\n",
    "from nltk.tag.stanford import StanfordNERTagger\n",
    "\n",
    "\n",
    "ner_path = '/usr/local/share/stanford-ner/'\n",
    "\n",
    "sentence = u\"Twenty miles east of Reno, Nev., \" \\\n",
    "    \"where packs of wild mustangs roam free through \" \\\n",
    "    \"the parched landscape, Tesla Gigafactory 1 \" \\\n",
    "    \"sprawls near Interstate 80.\"\n",
    "\n",
    "jar = '/usr/local/share/stanford-ner/stanford-ner.jar'\n",
    "\n",
    "       /usr/local/share/stanford-ner/stanford-ner-tagger/stanford-ner.jar\n",
    "\n",
    "model = '/usr/local/share/stanford-ner/classifiers/english.all.3class.distsim.crf.ser.gz'\n",
    "\n",
    "# Prepare NER tagger with english model\n",
    "ner_tagger = StanfordNERTagger(model, jar, encoding='utf8')\n",
    "\n",
    "# Tokenize: Split sentence into words\n",
    "words = nltk.word_tokenize(sentence)\n",
    "\n",
    "# Run NER tagger on words\n",
    "print(ner_tagger.tag(words))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[('En', 'O'), ('2017', 'DATE'), (',', 'O'), ('une', 'O'), ('intelligence', 'O'), ('artificielle', 'O'), ('est', 'O'), ('en', 'O'), ('mesure', 'O'), ('de', 'O'), ('développer', 'O'), ('par', 'O'), ('elle-même', 'O'), ('Super', 'PERSON'), ('Mario', 'PERSON'), ('Bros.', 'O'), ('Sans', 'O'), ('avoir', 'O'), ('eu', 'O'), ('accès', 'O'), ('au', 'O'), ('code', 'O'), ('du', 'O'), ('jeu', 'O'), (',', 'O'), ('elle', 'O'), ('a', 'O'), ('récrée', 'O'), ('ce', 'O'), ('hit', 'O'), ('des', 'O'), ('consoles', 'O'), ('Nintendo', 'ORGANIZATION'), ('.', 'O'), ('Des', 'O'), ('chercheurs', 'O'), ('de', 'O'), (\"l'Institut\", 'ORGANIZATION'), ('de', 'ORGANIZATION'), ('Technologie', 'ORGANIZATION'), ('de', 'O'), ('Géorgie', 'LOCATION'), (',', 'O'), ('aux', 'O'), ('Etats-Unis', 'LOCATION'), (',', 'O'), ('viennent', 'O'), ('de', 'O'), ('la', 'O'), ('mettre', 'O'), ('à', 'O'), (\"l'épreuve\", 'O'), ('.', 'O')]\n"
     ]
    }
   ],
   "source": [
    "import nltk\n",
    "from nltk.tag.stanford import StanfordNERTagger\n",
    "\n",
    "# Optional\n",
    "import os\n",
    "java_path = \"/usr/lib/jvm/java-8-oracle\"\n",
    "os.environ['JAVA_HOME'] = java_path\n",
    "\n",
    "sentence = u\"En 2017, une intelligence artificielle est en mesure de développer par elle-même Super Mario Bros. \" \\\n",
    "    \"Sans avoir eu accès au code du jeu, elle a récrée ce hit des consoles Nintendo. Des chercheurs de l'Institut \" \\\n",
    "    \"de Technologie de Géorgie, aux Etats-Unis, viennent de la mettre à l'épreuve.\"\n",
    "\n",
    "jar = f'{ner_path}stanford-ner.jar'\n",
    "model = f'{ner_path}dummy-ner-model-french.ser.gz'\n",
    "\n",
    "ner_tagger = StanfordNERTagger(model, jar, encoding='utf8')\n",
    "\n",
    "words = nltk.word_tokenize(sentence)\n",
    "print(ner_tagger.tag(words))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[('La', 'O'), ('première', 'O'), ('Falcon', 'O'), ('Heavy', 'O'), ('de', 'O'), (\"l'entreprise\", 'O'), ('SpaceX', 'O'), (',', 'O'), ('la', 'O'), ('plus', 'O'), ('puissante', 'O'), ('fusée', 'O'), ('des', 'O'), ('Etats-Unis', 'O'), ('jamais', 'O'), ('lancée', 'O'), ('depuis', 'O'), ('plus', 'O'), ('de', 'O'), ('quarante', 'O'), ('ans', 'O'), (',', 'O'), ('devrait', 'O'), ('bien', 'O'), ('emporter', 'O'), ('le', 'O'), ('roadster', 'O'), ('de', 'O'), (\"l'entrepreneur\", 'O'), ('américain', 'O'), (',', 'O'), ('mais', 'O'), ('sur', 'O'), ('une', 'O'), ('orbite', 'O'), ('bien', 'O'), ('différente', 'O'), ('.', 'O'), ('Elon', 'O'), ('Musk', 'O'), ('a', 'O'), ('le', 'O'), ('sens', 'O'), ('du', 'O'), ('spectacle', 'O'), ('.', 'O')]\n"
     ]
    }
   ],
   "source": [
    "sentence = u\"La première Falcon Heavy de l'entreprise SpaceX, \" \\\n",
    "    \"la plus puissante fusée des Etats-Unis jamais \" \\\n",
    "    \"lancée depuis plus de quarante ans, devrait bien \" \\\n",
    "    \"emporter le roadster de l'entrepreneur américain, \" \\\n",
    "\"mais sur une orbite bien différente. Elon Musk a le sens du spectacle.\"\n",
    "\n",
    "words = nltk.word_tokenize(sentence)\n",
    "print(ner_tagger.tag(words))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
